<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>产康预约</title>

  <#assign base=request.contextPath  />
    <base id="basePath" href="${base}">

    <base id="basePath" href="${base}">
    <link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>


    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${base}/js/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>

</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>产康预约</legend>
</fieldset>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">可预约</li>
        <li onclick="home2Chang()">已预约</li>
    </ul>
    <div class="layui-tab-content" style="height: 100px;">
        <div class="layui-tab-item layui-show">
            <div class="layui-tab-content">
                <div class="demoTable">
                    <div class="layui-inline">
                        <input  class="layui-input isNull" lay-verify="required" name="id" id="demoReload" placeholder="请输入姓名"  autocomplete="off">
                    </div>
                </div>
                <table class="layui-table" lay-data="{toolbar: '#toolbarDemo'
                                                           ,defaultToolbar: ['filter', 'print', 'exports']
                                                           ,page: {layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                                           ,theme: '#0092EF'
                                           ,limit:20

                                         } ,height:500 ,id: 'keYuYue',where: {stat: '1'}
                                         ,url: '${base}/production/selectProduction'}" >
                    <thead>
                    <tr>
                        <th lay-data="{field:'id', templet:function(val){return val.LAY_INDEX},align: 'center'}">id</th>
                        <th lay-data="{field:'project', align: 'center'}">产康项目</th>
                        <th lay-data="{field:'pice',align: 'center'}">价格</th>
                        <th lay-data="{field:'appointment',templet:function(val){if(val.appointment=='1'){return '可预约';}else{return '不可预约';
                                                                }},align: 'center'}">状态</th>
                        <th lay-data="{field: 'right', align: 'center', toolbar: '#barDemo'}">操作</th>
                    </tr>
                    </thead>
                </table>
                <script type="text/html" id="barDemo">
                    {{#  if(d.appointment ==1){ }}
                    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" style="Color:red;" href="javascript:void(0)"  onclick="Reservable('{{d.id}}','{{d.project}}','{{d.pice}}')">预约</a>
                    {{#  } else { }}
                    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" style="Color:blue;">不可预约</a>-->
                    {{#  } }}
                </script>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="layui-tab-content">

            </div>
            <table class="layui-hide" id="table_baby" lay-filter="user"></table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">可预约</a>
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">不可预约</a>
            </script>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo111">
    <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" id="delectbaby" href="javascript:void(0)"  onclick="onDelete('{{d.id}}')"  style="font-size: 20px;" ></i>
</script>
<script src="${base}/js/layui/layui.js" charset="utf-8"></script>
<script src="${base}/js/jquery.min.js"></script>
<script>

    layui.use(['element','table'], function(){
        var table = layui.table
        var $ = layui.jquery
                ,element = layui.element;
        table.render({
            elem: '#table_baby'
            ,url: '${base}/relationProject/findProjectByUserName'//数据接口
            ,cols: [[
                {field:'id',templet:function(val){
                        return val.LAY_INDEX
                    }, title: 'ID',align:'center'}
                ,{field:'project', title: '产康项目',align:'center'}
                ,{field:'pice', title: '价格',align:'center'}
                ,{field:'userName', title: '预约人',align:'center'}
                ,{field: 'right', title:'操作', toolbar: '#barDemo111', width:100, align: 'center'}
            ]]
            ,id: 'testReload'
            ,height: 500
            ,page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                ,theme: '#0092EF'
                ,limit:20
            }


            ,where:{"homeId":$("#home2").val()}
            ,height:500
            ,done: function(res, curr, count){
                this.where={};
            }



        });

//事件绑定
        layui.form.on('select(home2)', function(data){
            home2Chang();
        });
    });


    //触发事件
    var active = {
        tabChange: function(){
            //切换到指定Tab项
            element.tabChange('demo', '22');
        }
    };


    // 预约
    function Reservable(projectId,projectName,pice){
        if($("#demoReload").val()==0){
            //layui提示框
            layer.msg("请输入姓名");
            return;
        }

        var  userName=$("#demoReload").val()


        $.ajax({
            type:"POST",
            url:"${base}/externalAlready/addMoenyDtatiled",
            data:{"projectId":projectId,"userName":userName,"projectName":projectName,"pice":pice},
            async:false,
            success:function(data){
                //弹出提示框
                layer.msg(data);


            }
        });
    }
    //第二个选项卡的选择事件
    function home2Chang(){
        var homeId=$("#home2").val()
        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/relationProject/findProjectByUserName'
            //    ,where: {"homeId":homeId} //设定异步数据接口的额外参数
            //height: 300
        });
    }
    //搜索

    $('#btn1').on('click', function(){

        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/externalAlready/findExternalAlready'
            ,where:{"Param":$('#demoReload').val}
        });
    });

    //删除
    function onDelete(id){
//提示是否删除这条数据
//data里边的customerId是需要和实体类里边的id是一样的,不然是传不过来参数的
        layer.confirm('真的要删除吗?',function(index){
            $.ajax({
                type:"POST",
                url:"${base}/relationProject/delete",
                data:{"id":id},
                sync:false,
                success:function(data){
                    //alert("删除成功")
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url:'${base}/relationProject/findProjectByUserName'
                        ,where: {} //设定异步数据接口的额外参数
                    });
                    //关闭删除是否删除的提示框
                    layer.close(index);
                }
            });
        });
    }

</script>

</body>
</html>